﻿namespace FluentMvc
{
    using System;
    using System.Collections.Generic;
    using System.Linq.Expressions;
    using MvcIntegration;

    public class ModelContext<TModel> where TModel : class
    {
        internal readonly Dictionary<string, PropertySetting<TModel>> PropertySettings = new Dictionary<string, PropertySetting<TModel>>();

        internal PropertySetting<TModel> GetSettings(string propertyName)
        {
            if (!PropertySettings.ContainsKey(propertyName))
                PropertySettings.Add(propertyName, new PropertySetting<TModel>());
            return PropertySettings[propertyName];
        }

        public StringRulesConfiguration<TModel> RulesFor(Expression<Func<TModel, string>> selector)
        {
            return new StringRulesConfiguration<TModel>(selector, this);
        }

        public DateTimeRulesConfiguration<TModel, DateTime> RulesFor(Expression<Func<TModel, DateTime>> selector)
        {
            return new DateTimeRulesConfiguration<TModel, DateTime>(selector, this);
        }

        public DateTimeRulesConfiguration<TModel, DateTime?> RulesFor(Expression<Func<TModel, DateTime?>> selector)
        {
            return new DateTimeRulesConfiguration<TModel, DateTime?>(selector, this);
        }

        public BooleanRulesConfiguration<TModel, bool> RulesFor(Expression<Func<TModel, bool>> selector)
        {
            return new BooleanRulesConfiguration<TModel, bool>(selector, this);
        }

        public BooleanRulesConfiguration<TModel, bool?> RulesFor(Expression<Func<TModel, bool?>> selector)
        {
            return new BooleanRulesConfiguration<TModel, bool?>(selector, this);
        }

        public NumericRulesConfiguration<TModel, TProperty> RulesFor<TProperty>(Expression<Func<TModel, TProperty>> selector)
        {
            return new NumericRulesConfiguration<TModel, TProperty>(selector, this);
        }

        public TemplateConfiguration<TModel,TProperty> TemplatesFor<TProperty>(Expression<Func<TModel,TProperty>> selector)
        {
            return new TemplateConfiguration<TModel, TProperty>(selector, this);
        }
    }
}